package com.comparyinfo.service;

import com.comparyinfo.entity.Xinwen;
import com.comparyinfo.util.JdbcUtil;

import java.util.List;

public class XinwenService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into xinwen(title,content,xdate) values(?,?,now()) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param obj
     * @return
     */
    public List<Xinwen> getListAll(Xinwen obj) {
        String sql="select * from xinwen where 1=1 ";
        List<Xinwen> dblist= JdbcUtil.executeQuery(sql,null,Xinwen.class);
        return dblist;
    }



    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update xinwen set title=?,content=? where id=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param id
     * @return
     */
    public Xinwen getId(String id) {
        String sql="select * from xinwen where id="+id;
        List<Xinwen> users= JdbcUtil.executeQuery(sql,null,Xinwen.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from xinwen  where id=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
